


class Solution {
    public ListNode addTwoNumbers(ListNode l1, ListNode l2) {
        ListNode newHead = new ListNode() ;
         ListNode cur1 = l1 ;
         ListNode cur2 = l2 ;
         ListNode newEnd = newHead ;
         int num = 0 ;

         while(cur1!=null||cur2!=null || num != 0){
            ListNode node = new ListNode();
          if(cur1!=null && cur2!=null){
              int sum = (cur1.val + cur2.val + num)%10 ;
              node.val = sum  ;
              num =  (cur1.val + cur2.val + num )/10 ;
              newEnd.next = node ;
               newEnd = node ;
               cur1 = cur1.next ;
               cur2 = cur2.next ;
            }else if(cur2 == null&&cur1!=null){
                int sum = (cur1.val + num)%10 ;
               node.val = sum ;
               num =(cur1.val + num)/10   ;
               newEnd.next = node ;
               newEnd = node ;
               cur1 = cur1.next ;
            }else if(cur1 == null&&cur2!=null){
                int sum = (cur2.val + num)%10 ;
               node.val = sum;
               num =(cur2.val + num)/10 ;
               newEnd.next = node ;
               newEnd = node ;
               cur2 = cur2.next ;
            }else if(cur1==null && cur2==null){
              node.val = num ;
              newEnd.next = node ;
              newEnd = node ;
               num = 0;
            }
         }         
        

         return newHead.next ;
    }
}